package com.example.back.service;

import com.example.back.mapper.PostMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class TimeService {

    @Autowired
    private PostMapper postMapper;

    /**
     * 每天中午12点自动执行
     */
    @Scheduled(cron = "0 0 0 * * ?")
    public void resetDailyBrowseCount() {
        try {
            int affectedRows = postMapper.resetDayBrowse();
            log.info("成功重置日浏览量，影响行数: {}", affectedRows);
        } catch (Exception e) {
            log.error("重置日浏览量失败", e);
        }
    }
}

